﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Liabilities_Expenditure.ascx.cs" Inherits="ERP.Modules.Liabilities_Expenditure" %>
<script type="text/javascript">
    var indMoney = function (v) {
        v = (Math.round((v - 0) * 100)) / 100;
        v = (v == Math.floor(v)) ? v + ".00" : ((v * 10 == Math.floor(v * 10)) ? v + "0" : v);
        v = String(v);
        var ps = v.split('.'),
            whole = ps[0],
            sub = ps[1] ? '.' + ps[1] : '.00',
            r = /(\d+)(\d{3})/;
        while (r.test(whole)) {
            whole = whole.replace(r, '$1' + ',' + '$2');
        }
        v = whole;

        return v;
    };
    var NumCheck = function () {
        var x = window.App.txtSumPrice.getValue();
        var y = window.App.txtSumVAT.getValue();
        var k = window.App.txtShippingFee.getValue();
        var z = parseFloat(x.replace(/[,]/g, "")) + parseFloat(y.replace(/[,]/g, "")) + parseFloat(k.replace(/[,]/g, ""));
        window.App.txtSumTotalCash.setValue(z);
        window.App.txtShippingFee.setValue(FormatNumber(k));
    };
</script>
<%-------------------------------%>
<ext:Hidden ID="FormatTypeLiabilities_Expenditure" runat="server" />
<%--------------GridLiabilities_Expenditure-----------------%>
<ext:Panel runat="server" Layout="Fit" Border="False" ID="PanelLiabilities_Expenditure">
    <Content>
        <ext:GridPanel
            ID="grLiabilities_Expenditure"
            runat="server"
            Cls="grid-double"
            EnableColumnMove="true"
            Border="False">
            <Store>
                <ext:Store
                    ID="StoreLiabilities_Expenditure"
                    runat="server"
                    OnReadData="StoreLiabilities_Expenditure_RefreshData"
                    PageSize="20">
                    <Model>
                        <ext:Model ID="ModelLiabilities_Expenditure" runat="server" GroupField="Customer_Name">
                            <Fields>
                                <ext:ModelField Name="FullName" Type="String" />
                                <ext:ModelField Name="VoucherAmount" Type="Int" />
                                <ext:ModelField Name="Remain" Type="Int" />
                                <ext:ModelField Name="Have_Expenditure" Type="Int" />
                                <ext:ModelField Name="Order_Buy_DateBegin" Type="Date" />
                                <ext:ModelField Name="Order_Buy_Code" Type="String" />
                                <ext:ModelField Name="ReceiptReasonName" Type="String" />
                                <ext:ModelField Name="Customer_Alias" Type="String" />
                                <ext:ModelField Name="Customer_Name" Type="String" />
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:RowNumbererColumn runat="server" Text="STT" Width="30" Align="Center" />
                    <ext:Column runat="server" Text="Người mua" Width="130" DataIndex="FullName"/>
                    <ext:Column runat="server" Text="Chứng từ" Width="100" DataIndex="Order_Buy_Code"/>
                    <ext:DateColumn runat="server" Text="Ngày mua" Width="100" DataIndex="Order_Buy_DateBegin" Format="dd-MM-yyyy"/>
                    <ext:Column runat="server" Text="Mã NCC" Width="100" DataIndex="Customer_Alias"/>
                    <ext:Column runat="server" Text="Nhà cung cấp" Width="180" DataIndex="Customer_Name"/>
                    <ext:Column runat="server" Text="Phải chi" Width="100" DataIndex="VoucherAmount">
                        <Renderer Handler="return indMoney(value);" />
                    </ext:Column>
                    <ext:Column runat="server" Text="Đã chi" Width="100" DataIndex="Have_Expenditure">
                        <Renderer Handler="return indMoney(value);" />
                    </ext:Column>
                    <ext:Column runat="server" Text="Còn lại" Width="100" DataIndex="Remain">
                        <Renderer Handler="return indMoney(value);" />
                    </ext:Column>
                    <ext:Column runat="server" Text="Loại" Width="100" DataIndex="ReceiptReasonName" Flex="1"/>
                </Columns>
            </ColumnModel>
            <Features>
                <ext:Grouping
                    runat="server" 
                    HideGroupedHeader="true"
                    GroupByText="Xem theo phân nhóm"
                    ShowGroupsText="Phân nhóm"
                    GroupHeaderTplString="{name} ({rows.length} danh mục con {[values.rows.length > 1 ? '' : '']})"
                    StartCollapsed="True" />
            </Features>
            <View>
                <ext:GridView runat="server" StripeRows="true" />
            </View>
            <DockedItems>
                <ext:Toolbar ID="ToolbarTopMain" runat="server" Dock="Top">
                    <Items>
                        <ext:Button ID="btnExport" runat="server" Text="Xuất tập tin" Icon="Printer">
                            <Menu>
                                <ext:Menu ID="MenuMain" runat="server">
                                    <Items>
                                        <ext:MenuItem ID="MenuItemExportXML" runat="server" Text="XML" Icon="PageCode">
                                            <Listeners>
                                                <Click Handler="submitValue(#{grLiabilities_Expenditure}, #{FormatTypeLiabilities_Expenditure}, 'xml');" />
                                            </Listeners>
                                        </ext:MenuItem>
                                    </Items>
                                </ext:Menu>
                            </Menu>
                        </ext:Button>
                        <ext:ToolbarSeparator />
                        <ext:SelectBox
                            ID="SelectBoxLiabilitiesExpenditure"
                            runat="server"
                            Cls="x-select-box"
                            DisplayField="Customer_Name"
                            ValueField="Customer_ID"
                            MarginSpec="0 8 0 0"
                            EmptyText="Chọn nhà cung cấp">
                            <Store>
                                <ext:Store ID="StoreLiabilitiesExpenditure" runat="server">
                                    <Model>
                                        <ext:Model runat="server">
                                            <Fields>
                                                <ext:ModelField Name="Customer_Name" />
                                                <ext:ModelField Name="Customer_ID" />
                                            </Fields>
                                        </ext:Model>
                                    </Model>
                                </ext:Store>
                            </Store>
                            <DirectEvents>
                                <Select OnEvent="SelectBoxLiabilitiesExpenditure_Change">
                                    <EventMask ShowMask="true" Msg="Đang tải..."></EventMask>
                                </Select>
                            </DirectEvents>
                        </ext:SelectBox>
                        <ext:ToolbarSeparator />
                        <ext:DateField ID="txtDateBeginFillter" EmptyText="Từ ngày" runat="server" MarginSpec="0 8 0 0"/>
                        <ext:DateField ID="txtDateEndFillter" EmptyText="Đến ngày" runat="server" MarginSpec="0 5 0 0"/>
                        <ext:Button ID="btnFillter" runat="server" Text="Lọc" Icon="ApplicationGo" ToolTip="Chọn lọc theo ngày đặt hàng">
                            <DirectEvents>
                                <Click OnEvent="btnFillter_Click">
                                    <EventMask ShowMask="true" Msg="Đang tải..." />
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
                <ext:Toolbar ID="ToolbarPagging" runat="server" Dock="Bottom" AnchorHorizontal="100%">
                    <Items>
                        <ext:TriggerField ID="txtSearch" runat="server" Width="200" EnableKeyEvents="true" MarginSpec="0 8 0 0">
                            <Triggers>
                                <ext:FieldTrigger Icon="Search" />
                            </Triggers>
                            <DirectEvents>
                                <TriggerClick OnEvent="Search_Event"></TriggerClick>
                                <SpecialKey OnEvent="Search_Event" Before="return e.getKey() == Ext.EventObject.ENTER;">
                                     <EventMask ShowMask="true" Msg="Đang tải..." />
                                </SpecialKey>
                            </DirectEvents>
                        </ext:TriggerField>
                        <ext:PagingToolbar ID="PagingToolbarLiabilities_Expenditure" runat="server" StoreID="StoreLiabilities_Expenditure" BeforePageText="Trang" AfterPageText="của {0}" LastText="Cuối" NextText="Kế tiếp" PrevText="Trở lại" FirstText="Đầu" RefreshText="Làm tươi" DisplayInfo="true" DisplayMsg="Trang {0} - {1} của {2}" />
                    </Items>
                </ext:Toolbar>
            </DockedItems>
        </ext:GridPanel>
    </Content>
</ext:Panel>